@extends('layouts.template')

@section('title', '管理后台')

@section('content')

    <script type="text/javascript" charset="utf-8" src="{{asset('js/ueditor/ueditor.config.js')}}"></script>
    <script type="text/javascript" charset="utf-8" src="{{asset('js/ueditor/ueditor.all.min.js')}}"> </script>
    <script>
        var selectedMenu = 'article/all';
        var selectedTitle = '编辑文章';

        $(function(){

            var form = new Vue({
                el:'#div',
                data:{
                    cat_id:'{{$article->cat_id}}',
                },
                computed:{
                },
                mounted:function(){
                },
                watch: {
                },
                methods:{
                },
                components:{
                }
            });

            var ue = UE.getEditor('editor',{
                toolbars: [[
                    'fullscreen', 'source', '|', 'undo', 'redo', '|',
                    'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                    'directionalityltr', 'directionalityrtl', 'indent', '|',
                    'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                    'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                    'simpleupload', 'insertimage', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'insertframe', 'pagebreak', 'template', 'background', '|',
                    'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
                    'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                    'print', 'preview', 'searchreplace', 'drafts', 'help'
                ]]
            });

            var validator = $("#form").validate({
                rules: {
                    title:{
                        required:true,
                        minlength:1,
                        maxlength:20,
                    },
                    cat_id:{
                        required:true,
                    },
                    content:{
                        required:true,
                        minlength:5,
                    },
                },
                messages: {
                    title:{
                        required:'请填写标题',
                        maxlength:'不要超过20个字',
                    },
                    cat_id:{
                        required:'请选择分类',
                    },
                    content:{
                        required:'请填写内容',
                    },
                },
                submitHandler: function(form) {
                    form.submit();
                },
            });

        });

    </script>

    <div class="col-md-9" id="div">
        <form id="form" method="POST" action="">
            {{csrf_field()}}
            <div class="panel panel-default">
                <div class="panel-body">
                    <!-- 左侧表单 begin-->
                    <div class="col-md-6">
                        <div class="row">

                            <div class="form-group">
                                <label class="col-sm-3 control-label">文章标题： <span class="asterisk">*</span></label>
                                <div class="col-sm-9">
                                    <input type="text" name="title" class="form-control" required="required" value="{{$article->title}}">(不要超过20个字)
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">分类： <span class="asterisk">*</span></label>
                                <div class="col-sm-9">
                                    <select v-model="cat_id" name="cat_id" class="select-search-hide width300 select2-offscreen">
                                        <option value="" selected="selected">请选择</option>
                                        @foreach ($categries as $key=>$text)
                                            <option value="{{$key}}" v-if="'{{$key}}' == cat_id" selected="selected">{{$text}}</option>
                                            <option value="{{$key}}" v-else>{{$text}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-3 control-label">内容： <span class="asterisk">*</span></label>
                                <div class="col-sm-9">
                                    {{--<textarea rows="5" name="content" class="form-control"></textarea>--}}
                                    <script id="editor" type="text/plain" style="width:600px;height:500px;"  name="content">{!! $article->content !!}</script>
                                </div>
                            </div>

                        </div><!-- row -->
                    </div>
                    <!-- 左侧表单 end-->
                </div><!-- panel-body -->
                <div class="panel-footer">
                    <div class="row">
                        <div class="col-sm-9 col-sm-offset-3">
                            <button class="btn btn-primary mr5" type="submit">保存</button>
                            <a href="{{$_refer}}" class="btn btn-dark">取消</a>
                        </div>
                    </div>
                </div><!-- panel-footer -->
            </div><!-- panel -->
        </form>
    </div>


@endsection

